<template>
  <div class="body" v-loading="loading">
    <div>
      <el-button type="info" size="small" icon="el-icon-back" @click="gotoList">&nbsp;返&nbsp;回&nbsp;</el-button>
    </div>
    <el-form ref="form" :model="header" size="small" label-width="80px" :inline="true" class="header">
      <div class="header_row">
        <el-form-item style="width:200px;" label="追溯码数">{{ header.codeCount }}</el-form-item>
        <el-form-item style="width:200px;" label="启用数量">{{ header.enabledCount }}</el-form-item>
        <el-form-item style="width:200px;" label="未启数量">{{ header.noEnabledCount }}</el-form-item>
        <el-form-item style="width:200px;" label="创建人员">{{ header.createUserName }}</el-form-item>
        <el-form-item style="width:300px;" label="创建时间">{{ header.createTime }}</el-form-item>
      </div>
    </el-form>
    <el-table :data="dataList" class="detail" height="calc(100vh - 180px)">
      <el-table-column label="No." width="60" align="right" type="index"></el-table-column>
      <el-table-column label="追溯码" min-width="160" prop="traceabilityCode">
        <template #default="scope">
          {{ subStr(scope.row.traceabilityCode) }}
        </template></el-table-column>
      <el-table-column label="二维码" min-width="160" prop="traceabilityCode">
        <template #default="scope">
          {{ scope.row.traceabilityCode }}
        </template></el-table-column>
      <el-table-column label="启用状态" width="250" align="center">
        <template #default="scope">
          <el-tag :type="scope.row.enableStatus? 'info': 'success'">{{ scope.row.enableStatus? '已启用': '未启用' }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="箱号" min-width="160" prop="boxNo"></el-table-column>
      <el-table-column label="rfid" min-width="160" prop="rfid"></el-table-column>
    </el-table>
  </div>
</template>

<script>
import dayjs from 'dayjs'
import { getBoxNo } from '../../utils'
import BatchAddRowDialog from "../components/batchAddRowDialog.vue";

export default {
  data() {
    return {
      loading: false,
      header: {},
      dataList: [],
    }
  },
  async mounted() {
    let id = this.$route.query.id
    if (id) {
      return this.getBill(id)
    }
  },
  methods: {
    subStr(str) {
      if (!str) return ""
      return str.substring(str.indexOf('=') + 1)
    },
    gotoList() {
      return this.$router.push('/basic/traceabilityCodeList')
    },
    async getBill(id) {
      this.loading = true
      try {
        let res = await this.callApi('get_traceability_code_detail', { id })
        if (res.res) {
          this.header = res.header || {}
          this.dataList = res.data || []
        }
      } finally {
        this.loading = false
      }
    },
  }
}
</script>

<style lang="scss" scoped>
.body {
  padding: 20px 0;
  .header {
    margin-top: 20px;
    position: relative;
    .header_row {
      display: flex;
      >div {
        flex-shrink: 0;
      }
      :deep(.produceDate) {
        .el-input {
          width: 100%!important;
        }
      }
    }
    .audit_icon {
      position: absolute;
      top: -10px;
      left: 60px;
      font-size: 48px;
      color: red;
    }
    .material {
      width: 100%;
    }
    .p3 {
      :deep(.el-form-item__content) {
        display: flex;
        .comment {
          margin-left: 10px;
          word-break: keep-all;
        }
      }
    }
  }
  .detail_header {
    display: flex;
    justify-content: space-between;
    margin-top: 10px;
    .stat {
      display: flex;
      font-size: 15px;
      >div {
        display: flex;
        align-items: baseline;
        line-height: 32px;
        .label {
          text-align: right;
          margin-right: 5px;
          color: #aaa;
        }
        .value {
          min-width: 50px;
          margin-right: 10px;
          color: #666;
        }
      }
    }
  }
}
</style>
